#ifndef _jammit_GridCompareWin_h_
#define _jammit_GridCompareWin_h_

// My creation:  Allows easier cloning of window pages
#undef WINNAME
#define WINNAME GridCompareWin

/*
  About window with some features: Remembers position, modeless so can leave open, copyable information
*/
#include "PowerWindow.h" // Contains TopWindow
#include "PowerArray.h" // Allow us to traverse the playlist and cherrypick songs to look at
#include "TagHandler.h" // All our tools for working with tags
#include "MainWinIDs.h" // We have to reference the columns on the main list to pull into a vector.

// U++ connection
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

class MainWin;  // We reference functions in the main set.

class GridCompareWin : public WithGridCompareLayout<PowerWindow> {

public:
	StaticMutex mutex;
	PowerArray *selectedList;
	int listIndex;
	TagHandler tagHandler;
	
	typedef GridCompareWin CLASSNAME;

	//============================================================================================================================
	//  Grid Compare Window - Constructor
	//  Build the three grids that each show a set of tags from a form of the song: The file tags vs. the database tags vs. what 
	//  we suggest setting them to.
	//============================================================================================================================
	GridCompareWin() {
		RTIMING(String().Cat() << "Creating " << QUOTEME(WINNAME));
		// Following must be in constructor or will abort on 2nd open
		CtrlLayout(*this);
		FormGrid(lstFile);
		FormGrid(lstOldDb);
		FormGrid(lstNewDb);
	}

	//============================================================================================================================
	~GridCompareWin() {
		RTIMING(String().Cat() << "Destroying " QUOTEME(WINNAME));
	}

	//============================================================================================================================
	void Open() {
		PowerWindow::Open("gridcomparewin");
	}

	//============================================================================================================================
	void Close() {
		PowerWindow::Close("gridcomparewin");
	}

	//============================================================================================================================
	virtual void Xmlize(XmlIO xml) {
		
	}
	
	//============================================================================================================================
	//  Since all three grids are identical, we can share a factory function.
	//============================================================================================================================
	void FormGrid(GridCtrl &grid) {
		grid.Editing();
		grid.Absolute();
		grid.AddColumn(IDTitle, "Title").Width(80);
		grid.AddColumn(IDArtistName, "Artist").Width(80);
		grid.AddColumn(IDAlbumName, "Album").Width(80);
		grid.AddColumn(IDGenreName, "Genre").Width(80);
		grid.WhenChangeRow = THISBACK1(SyncToUserSelection, &grid);
	}

	//============================================================================================================================
	//  When user selects a row of tags from one form state, we align the other forms of the tags for comparison visually.
	//============================================================================================================================
	void SyncToUserSelection(GridCtrl *drivingGrid) {
		int targetRow = drivingGrid->GetCursor();
		lstFile.SetCursor(targetRow);
		lstFile.CenterCursor();
		lstOldDb.SetCursor(targetRow);
		lstOldDb.CenterCursor();
		lstNewDb.SetCursor(targetRow);
		lstNewDb.CenterCursor();
	}

};


#endif
